package com.example.myapplication;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.example.myapplication.model.Teacher;
import java.util.List;

public class TeacherAdapter extends BaseAdapter {
    private Context context;
    private List<Teacher> teacherList;

    public TeacherAdapter(Context context, List<Teacher> teacherList) {
        this.context = context;
        this.teacherList = teacherList;
    }

    @Override
    public int getCount() {
        return teacherList.size();
    }

    @Override
    public Object getItem(int position) {
        return teacherList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_course, parent, false);
            holder = new ViewHolder();
            holder.textViewTeacherName = convertView.findViewById(R.id.textViewItemCourseName);
            holder.textViewTeacherInfo = convertView.findViewById(R.id.textViewItemTeacherName);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Teacher teacher = teacherList.get(position);
        holder.textViewTeacherName.setText(teacher.getName());
        holder.textViewTeacherInfo.setText(teacher.getInfo());
        return convertView;
    }

    static class ViewHolder {
        TextView textViewTeacherName;
        TextView textViewTeacherInfo;
    }
}
